package ace.module.weixin.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.module.weixin.api.model.dto.WxsMiniAppConfigDto;
import ace.module.weixin.core.impl.dao.entity.WxsMiniAppConfig;
import ace.module.weixin.core.impl.manager.WxsMiniAppConfigManager;
import ace.module.weixin.core.impl.manager.cache.WxsMiniAppConfigCacheManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 微信小程序配置 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class WxsMiniAppConfigManagerImpl
    extends AbstractSpringDtoManager<WxsMiniAppConfig, Long, WxsMiniAppConfigDto>
    implements WxsMiniAppConfigManager {

  private final WxsMiniAppConfigCacheManager wxsMiniAppConfigCacheManager;

  @Override
  public WxsMiniAppConfig getByAppIdFromDbOrCache(String appId) {
    return wxsMiniAppConfigCacheManager.getByAppIdAnDeleteFlagIsNot(appId);
  }

  @Override
  public void saveOrUpdateDbAndCache(WxsMiniAppConfig wxsMiniAppConfig) {
    this.wxsMiniAppConfigCacheManager.saveOrUpdate(wxsMiniAppConfig);
  }
}
